package eleventh.国际化程序.处理动态文本;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

public class 使用MessageFormat格式化动态文本 {
    public static void main(String[] args) {
        Locale zhLoc = new Locale("zh", "CN1");
        Locale enLoc = new Locale("en", "US1");
        Locale frLoc = new Locale("fr", "FR1");
        //找到对应语言的属性文件
        ResourceBundle zhrb = ResourceBundle.getBundle("Message", zhLoc);
        ResourceBundle enrb = ResourceBundle.getBundle("Message", enLoc);
        ResourceBundle frrb = ResourceBundle.getBundle("Message", frLoc);
        //依次读取各个属性的值，通过键值读取，此时的键值名称为”Info“
        String str1 = zhrb.getString("info");
        String str2 = enrb.getString("info");
        String str3 = frrb.getString("info");
        //设置动态文本的内容
        System.out.println("中文："+ MessageFormat.format(str1,"王境泽"));
        System.out.println("英文："+ MessageFormat.format(str2,"WangJZ"));
        System.out.println("法文："+ MessageFormat.format(str3,"WangJZ"));

    }
}
/**
 * Java新特性----可变参数传递中可以接收多个对象
 */
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=57078:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 eleventh.国际化程序.处理动态文本.使用MessageFormat格式化动态文本
中文：你好，王境泽！
英文：Hello,WangJZ!
法文：Bonjour,WangJZ!

Process finished with exit code 0
 */